Dynomotion

Group: DynoMotion Message: 13912 From: Greg Carter Date: 10/16/2016
Subject: Extended Logging for Kflop
Hello,

I've put up the source code to a project I made to handle logging and
plotting of kflop data over extended periods. So more than the 3.5
seconds that can be gathered using the step/response screen in kmotion.
I'm using this to tune my really slow/low precision axis. However I
tried to make it generic enough that you can use it to log and plot just
about anything from the kflop. Limitations include that the x axis is
assumed to be time (or any other incrementing value) that you wish to
plot the other variables against. It can do simple transforms on the
data (add/sub/mul/div), this could be extended to use more complex
formulas... but for now good enough to do error plots for command
position...

plots appear as the data is generated on the kflop

You can view plots side by side, sync their axis etc..

You can save and load the data into a blank plot.

Export to image file (png)

plot configuration can be saved and reused.

A session can be saved (what C files you have open for editing, and
current plots open), note however that currently the data is NOT coupled
to the saved session. You have to save the data generated for plot
separately, and load it manually after opening a previous session.

You might find it useful to track down problems in your system by
setting up a thread to trigger logging when some problem sequence run...

I'm still learning how the kflop API works so this may not play well
with other apps. One thing I have noticed is that the console handler
is a "last to register wins". So if you have two kflop apps running
(KmotionCNC and this logging app) the last one to start gets the
console. And this app requires the console to run. This may limit
the utility.

A small demo:

https://youtu.be/BisZrkeGMLM (sorry a bit of hum in a few places).

The source can be found here:

https://gitlab.com/Greg9504/ExtendedLoggingKflop

There is a readme.md with instructions on how it works and how to
download and install. Pre compiled binaries are for 4.34a. Use at your
own risk. Source is .net c#, the application is WPF, project is VS 2015.

For Tom

Some timing information for various log formats:

Control run, no printf just doing calculations in loop of 10000 - time
7.2 seconds

printf using %g (or %f) time - 10.8 seconds, max data rate 32 kB/sec,
printf("@0,%g,%g,%g,%g\n", tcurr.dValue, y1.dValue, y2.dValue, y3.dValue)

printf using hex dump, time - 14.4 seconds, max data rate 57 kB/sec ,
printf("@0,%08X%08X,%08X%08X,%08X%08X,%08X%08X\n", tcurr.iValue.iValue2,
tcurr.iValue.iValue1,
y1.iValue.iValue2, y1.iValue.iValue1,
y2.iValue.iValue2, y2.iValue.iValue1,
y3.iValue.iValue2, y3.iValue.iValue1);

sprintf using hex dump (data not transmitted), time - 14.4 seconds

To transmit as hex I define this struct:

typedef union _DoubleAsUInt_ {
double dValue;
struct iValue {
unsigned int iValue1;
unsigned int iValue2;
}iValue;
} DoubleAsUInt;

Then set the value using: DoubleAsUInt tcurr; tcurr.dValue = Time_sec()
- T0;

The printf using this shouldn't have any floating point math... but it
takes much longer to generate the buffer (sprintf takes just as long as
printf which has to send the data).

For now I've compiled the app to assume the data is in string format
(not hex). If you wish to test yourself set FromHex to true in the
PlotViewModel.cs constructor (~ line 95).
Group: DynoMotion Message: 13914 From: Tom Kerekes Date: 10/17/2016
Subject: Re: Extended Logging for Kflop

Hi Greg,

Wow what a great Job!

I was able to Clone it, Compile it, Run it, and make this simple plot of a move easily.

One thing that comes to mind right away would be this would be great for tuning multiple and slaved axes.


Not being familiar with VS Git Tools I must admit it took a while to figure out to do:

VS2015 | File | New Repository | Local Get Repository | Clone | https://gitlab.com/Greg9504/ExtendedLoggingKflop | C:\KMotion434a\PC VC Examples\ExtendedLoggingKflop | Clone

I was also missing the c program header:

#include "ExtendedLogging.h"

But just replaced with:

#include "KMotionDef.h"

Everything else just worked :)

Regarding the timing: I'm not sure I follow all that but printf/sprintf are probably not very well optimized.  KFLOP has an optimized routine:

        SendHex(*(int*)(&f));  

That can send a 32-bit int or float out the USB quickly.  We might try that if we ever need higher throughput.

Thanks!
TK


On 10/16/2016 8:43 PM, Greg Carter greg@... [DynoMotion] wrote:
 

Hello,

I've put up the source code to a project I made to handle logging and
plotting of kflop data over extended periods. So more than the 3.5
seconds that can be gathered using the step/response screen in kmotion.
I'm using this to tune my really slow/low precision axis. However I
tried to make it generic enough that you can use it to log and plot just
about anything from the kflop. Limitations include that the x axis is
assumed to be time (or any other incrementing value) that you wish to
plot the other variables against. It can do simple transforms on the
data (add/sub/mul/div), this could be extended to use more complex
formulas... but for now good enough to do error plots for command
position...

plots appear as the data is generated on the kflop

You can view plots side by side, sync their axis etc..

You can save and load the data into a blank plot.

Export to image file (png)

plot configuration can be saved and reused.

A session can be saved (what C files you have open for editing, and
current plots open), note however that currently the data is NOT coupled
to the saved session. You have to save the data generated for plot
separately, and load it manually after opening a previous session.

You might find it useful to track down problems in your system by
setting up a thread to trigger logging when some problem sequence run...

I'm still learning how the kflop API works so this may not play well
with other apps. One thing I have noticed is that the console handler
is a "last to register wins". So if you have two kflop apps running
(KmotionCNC and this logging app) the last one to start gets the
console. And this app requires the console to run. This may limit
the utility.

A small demo:

https://youtu.be/BisZrkeGMLM (sorry a bit of hum in a few places).

The source can be found here:

https://gitlab.com/Greg9504/ExtendedLoggingKflop

There is a readme.md with instructions on how it works and how to
download and install. Pre compiled binaries are for 4.34a. Use at your
own risk. Source is .net c#, the application is WPF, project is VS 2015.

For Tom

Some timing information for various log formats:

Control run, no printf just doing calculations in loop of 10000 - time
7.2 seconds

printf using %g (or %f) time - 10.8 seconds, max data rate 32 kB/sec,
printf("@0,%g,%g,%g,%g\n", tcurr.dValue, y1.dValue, y2.dValue, y3.dValue)

printf using hex dump, time - 14.4 seconds, max data rate 57 kB/sec ,
printf("@0,%08X%08X,%08X%08X,%08X%08X,%08X%08X\n", tcurr.iValue.iValue2,
tcurr.iValue.iValue1,
y1.iValue.iValue2, y1.iValue.iValue1,
y2.iValue.iValue2, y2.iValue.iValue1,
y3.iValue.iValue2, y3.iValue.iValue1);

sprintf using hex dump (data not transmitted), time - 14.4 seconds

To transmit as hex I define this struct:

typedef union _DoubleAsUInt_ {
double dValue;
struct iValue {
unsigned int iValue1;
unsigned int iValue2;
}iValue;
} DoubleAsUInt;

Then set the value using: DoubleAsUInt tcurr; tcurr.dValue = Time_sec()
- T0;

The printf using this shouldn't have any floating point math... but it
takes much longer to generate the buffer (sprintf takes just as long as
printf which has to send the data).

For now I've compiled the app to assume the data is in string format
(not hex). If you wish to test yourself set FromHex to true in the
PlotViewModel.cs constructor (~ line 95).


Group: DynoMotion Message: 13915 From: Greg Carter Date: 10/17/2016
Subject: Re: Extended Logging for Kflop
Hi Tom,

I forgot to check that in... I have now.  Although all it did was include KmotionDef.h and define some values that are not used in the samples.  If you do a git pull you should get the update.

I'm no git master either, but it seems to be what everyone is using these days.

I was worried that perhaps the printf's could "slow down" the processing of other operations on the kflop.  I'll clean up the test I made and send it to you.

Greg.

On 10/17/2016 5:34 PM, Tom Kerekes tk@... [DynoMotion] wrote:
 

Hi Greg,

Wow what a great Job!

I was able to Clone it, Compile it, Run it, and make this simple plot of a move easily.

One thing that comes to mind right away would be this would be great for tuning multiple and slaved axes.


Not being familiar with VS Git Tools I must admit it took a while to figure out to do:

VS2015 | File | New Repository | Local Get Repository | Clone | https://gitlab.com/Greg9504/ExtendedLoggingKflop | C:\KMotion434a\PC VC Examples\ExtendedLoggingKflop | Clone

I was also missing the c program header:

#include "ExtendedLogging.h"

But just replaced with:

#include "KMotionDef.h"

Everything else just worked :)

Regarding the timing: I'm not sure I follow all that but printf/sprintf are probably not very well optimized.  KFLOP has an optimized routine:

        SendHex(*(int*)(&f));  

That can send a 32-bit int or float out the USB quickly.  We might try that if we ever need higher throughput.

Thanks!
TK